

import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;

import com.vmware.vim25.InvalidProperty;
import com.vmware.vim25.PerfInterval;
import com.vmware.vim25.RuntimeFault;
import com.vmware.vim25.mo.PerformanceManager;
import com.vmware.vim25.mo.ServiceInstance;

public class PerformanceIntervals {

	static final String SERVER_NAME = "192.168.190.87";
	static final String USER_NAME = "Administrator";
	static final String PASSWORD = "xxxxxx";
	public static void main(String[] args) {
		String url = "https://" + SERVER_NAME + "/sdk/vimService";
		try {
			ServiceInstance si = new ServiceInstance(new URL(url), USER_NAME, PASSWORD, true);
			PerformanceManager perfMgr = si.getPerformanceManager();

			PerfInterval[] perfIntervals = perfMgr.getHistoricalInterval();
			for (PerfInterval perfInterval : perfIntervals) {
				System.out.println("key = " + perfInterval.getKey());
				System.out.println("length = " + perfInterval.getLength());
				System.out.println("samplingPeriod = " + perfInterval.getSamplingPeriod());
				System.out.println("level = " + perfInterval.getLevel());
				System.out.println("name = " + perfInterval.getName());
				System.out.println();
			}
			si.getServerConnection().logout();
		} catch (InvalidProperty e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RuntimeFault e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}